package ${packageAction};

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import ${packageService}.${serivceName};
import ${entityClass};

@Controller
@RequestMapping("${parentURL}")
@Api(tags = { "${businessName}操作接口" })
public class ${actionClass} {
	@Autowired
	private ${serivceName} ${serivceName?lower_case};

	@ApiOperation(value = "添加${businessName}", notes = "", httpMethod = "POST")
	@RequestMapping(value = "/add", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Object add(${className} param) {
		JSONObject obj = new JSONObject();
		try {
			${serivceName?lower_case}.add${className}(param);
			obj.put("success", true);
			obj.put("data", param);
		} catch (Exception e) {
			obj.put("message", e.getMessage());
			obj.put("success", false);
		}
		return obj;
	}

	@ApiOperation(value = "删除${businessName}", notes = "", httpMethod = "POST")
	@RequestMapping(value = "/delete", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Object delect(Integer[] ids) {
		JSONObject obj = new JSONObject();
		try {
			${serivceName?lower_case}.delete${className}s(ids);
			obj.put("success", true);
		} catch (Exception e) {
			obj.put("message", e.getMessage());
			obj.put("success", false);
		}
		return obj;
	}

	@ApiOperation(value = "修改${businessName}", notes = "", httpMethod = "POST")
	@RequestMapping(value = "/update", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Object update(${className} param) {
		JSONObject obj = new JSONObject();
		try {
			${serivceName?lower_case}.update${className}(param);
			obj.put("success", true);
		} catch (Exception e) {
			obj.put("message", e.getMessage());
			obj.put("success", false);
		}
		return obj;
	}

	@ApiOperation(value = "分页查询${businessName}", notes = "", httpMethod = "GET")
	@RequestMapping(value = "/query", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Object query(${className} param, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
		JSONObject obj = new JSONObject();
		try {
			Page<${className}> data = ${serivceName?lower_case}.findAll(page, size, param);
			obj.put("success", true);
			obj.put("data", data);
		} catch (Exception e) {
			obj.put("message", e.getMessage());
			obj.put("success", false);
		}
		return obj;
	}

}
